From fe385e6f13d8e707faca8b75e10caf8a6ae673b7 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Sun, 29 Mar 2015 04:45:46 +0000 Subject: [PATCH] Fix theoretical memory leak in tpo. Fix missing va_end in gpsserial (which matters on no modern arch) Fix actual copy/paste bug in ggv_ovl. --- gpsbabel/ggv_ovl.cc | 4 ++-- gpsbabel/jeeps/gpsserial.cc | 1 + gpsbabel/tpo.cc | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/gpsbabel/ggv_ovl.cc b/gpsbabel/ggv_ovl.cc index da45bcdc3..36171c445 100644 --- a/gpsbabel/ggv_ovl.cc +++ b/gpsbabel/ggv_ovl.cc @@ -137,11 +137,11 @@ ggv_ovl_read(void) if (group > 1) { route_add_head(rte); route_ct++; - trk->rte_name = QString("Route %1").arg(route_ct); + rte->rte_name = QString("Route %1").arg(route_ct); } else { track_add_head(trk); track_ct++; - trk->rte_name = QString("Track %1").arg(track_ct); + trk->rte_name = QString("Track %1").arg(track_ct); } for (j = 0; j < points; j++) { diff --git a/gpsbabel/jeeps/gpsserial.cc b/gpsbabel/jeeps/gpsserial.cc index 030077982..e510f540c 100644 --- a/gpsbabel/jeeps/gpsserial.cc +++ b/gpsbabel/jeeps/gpsserial.cc @@ -396,6 +396,7 @@ void GPS_Serial_Error(const char* mb, ...) // GetLastError(), 0, s, sizeof(msg) - b - 2, 0 ); strcat(msg, strerror(errno)); GPS_Error(msg); + va_end(ap); } int32 GPS_Serial_Read(gpsdevh* dh, void* ibuf, int size) diff --git a/gpsbabel/tpo.cc b/gpsbabel/tpo.cc index 13816f67c..90060fe57 100644 --- a/gpsbabel/tpo.cc +++ b/gpsbabel/tpo.cc @@ -77,6 +77,7 @@ #include #include #include +#include // Wish we could use c++11... #define MYNAME "TPO" @@ -491,7 +492,15 @@ Waypoint* tpo_convert_ll(int lat, int lon) } #define TRACKNAMELENGTH 256 -struct style_info { +class StyleInfo { +public: + StyleInfo() { + name[0] = 0; + color[0] = 0; + color[1] = 0; + color[2] = 0; + wide = dash = 0; + } char name[TRACKNAMELENGTH]; // some huge value uint8_t color[3]; // keep R/G/B values separate because line_color needs BGR uint8_t wide; @@ -506,7 +515,7 @@ void tpo_process_tracks(void) unsigned int track_count, track_style_count; unsigned int xx,ii,tmp; - int DEBUG=0; + const int DEBUG = 0; if (DEBUG) { printf("Processing Track Styles... (added in 2012 by SRE)\n"); @@ -523,7 +532,7 @@ void tpo_process_tracks(void) printf("Unpacking %d track styles...\n",track_style_count); } - style_info* styles = (style_info*)xcalloc(track_style_count, sizeof(style_info)); + QScopedArrayPointer styles(new StyleInfo[track_style_count]); for (ii = 0; ii < track_style_count; ii++) { @@ -787,8 +796,6 @@ void tpo_process_tracks(void) xfree(buf); } - xfree(styles); -//printf("\n"); } -- 2.30.2